package com.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.domain.Goods;
import com.service.GoodsService;
import com.service.Impl.GoodsServiceImpl;

@WebServlet("/singlyServlet")
public class singlyServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取展示商品否id值
        String id = request.getParameter("id");
        //创建实现类对象
        GoodsService goodsService = new GoodsServiceImpl();
        Goods goods = goodsService.findById(Integer.parseInt(id));
        //存入域中
        HttpSession session = request.getSession();
        session.setAttribute("goods", goods);
        //转发到商品详情页面
        request.getRequestDispatcher("/page/singly.jsp").forward(request, response);
    }
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}
}
